/*
 * @(#)SdeWriter.java $version 2012. 5. 31.
 *
 */

package com.mywep.myalimi.batch.sde;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;

import com.mywep.myalimi.model.NewContent;
import com.mywep.myalimi.repository.content.NewContentRepository;

/**
 * @author 한지웅
 */
public class SdeWriter implements ItemWriter<List<NewContent>> {
	private static final Logger LOG = LoggerFactory.getLogger(SdeWriter.class);
	@Autowired
	private NewContentRepository newContentRepository;
	/**
	 * @param arg0
	 * @throws Exception
	 * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
	 */
	@Override
	public void write(List<? extends List<NewContent>> arg0) throws Exception {
		for (List<NewContent> newContents : arg0) {
			for (NewContent newContent : newContents) {
				try {
					newContentRepository.deleteByPrimaryKey(newContent);
				} catch (Exception e) {
					LOG.error("{}", e);
					LOG.error("{}", newContent);
				}
			}
		}
	}

}
